﻿<?php
include 'config.php';
//include("xvideostj.php");
$y=$_GET['url'];
if($y==''){
	echo'error';
}
else{

$a=postData('https://www.xvideos.com'.$y,'');
$dt=getSubstr($a,'var video_related=',';window.wpn_categories');
$dt=str_replace("\\",'',$dt);
$dt='"data":'.$dt;
//tuijian*OK-------------------------------------------
$zp=getSubstr($a,"setVideoUrlLow('",'html5player.setThumbUrl');
$zp=str_replace('	','',$zp);
$zp=str_replace("');",'',$zp);
$zp=str_replace("html5player.setVideoUrlHigh('",'","mp42":"',$zp);
$zp=str_replace('','',$zp);
$zp=str_replace(array("\r\n", "\r", "\n"), '', $zp);
$zp='"mp41":"'.$zp.'"';
$m3u8=$zp.'<<<';
$m3u8=getSubstr($m3u8,"html5player.setVideoHLS('",'"<<<');
$p250=str_replace('hls.m3u8','hls-250p.m3u8',$m3u8);
$p360=str_replace('hls.m3u8','hls-360p.m3u8',$m3u8);
$p480=str_replace('hls.m3u8','hls-480p.m3u8',$m3u8);
$zp=str_replace("html5player.setVideoHLS('",'","m3u8":"',$zp);
$zp=$zp.',"250p":"'.$p250.'"'.',"360p":"'.$p360.'"'.',"480p":"'.$p480.'"';
//zp*ok------------------------------------------------
$json='{'.$zp.','.$dt.'}';
$json=str_replace('"u":"','"u":"'.$http,$json);
echo $json;
}





function postData($url, $data)
{
    $headers = array();
    $headers[] = ':authority:api.47ks.com';
    $headers[] = ':method:GET';
    $headers[] = ':path:/webcloud/?v=http://www.iqiyi.com/v_19rr7qhfg0.html';
    $headers[] = ':scheme:https';
    $headers[] = 'accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
    $headers[] = 'accept-encoding:gzip, deflate, sdch, br';
    $headers[] = 'accept-language:zh-CN,zh;q=0.8';
    $headers[] = 'referer:http://www.paload.cn/?url=http://www.iqiyi.com/v_19rr7qhfg0.html';
    $headers[] = 'upgrade-insecure-requests:1';
    $headers[] = 'user-agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36';
    $ch = curl_init();
    $timeout = 300;
    curl_setopt($ch, CURLOPT_URL, $url);
    //curl_setopt($ch, CURLOPT_REFERER, "http://127.0.0.1/");   //构造来路
	//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//构造http协议头
	
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $handles = curl_exec($ch);
    curl_close($ch);
    return $handles;
}
/*以下是取中间文本的函数 
getSubstr=调用名称
$str=预取全文本 
$leftStr=左边文本
$rightStr=右边文本
*/
function getSubstr($str, $leftStr, $rightStr)
{
    $left = strpos($str, $leftStr);
    //echo '左边:'.$left;
    $right = strpos($str, $rightStr,$left);
    //echo '<br>右边:'.$right;
    if($left < 0 or $right < $left) return '';
    return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));
}
?>